package com.red.controller.admin;

import com.red.dto.HomePageQueryDTO;
import com.red.entity.Attractions;
import com.red.result.PageResult;
import com.red.result.Result;
import com.red.service.AttractionsService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController("adminAttractionsController")
@RequestMapping("/admin/scenic")
@CrossOrigin(origins = "http://localhost:9527")
@Slf4j
@ApiModel(value = "管理端景点接口")
public class AttractionsController {
    @Autowired
    private AttractionsService attractionsService;


    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/pageQuery")
//    @CrossOrigin
    public Result<PageResult> pageQuery(HomePageQueryDTO dto){
        PageResult pageResult = attractionsService.AdminpageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增景点信息
     * @param attractions
     * @return
     */
    @PostMapping
    @CrossOrigin
    @ApiModelProperty("新增景点信息")
    public Result insert(@RequestBody Attractions attractions){
        log.info("新增景点：{}",attractions);

        attractionsService.insert(attractions);
        return Result.success();
    }

    /**
     * 根据ID删除景点
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @CrossOrigin
    @ApiModelProperty("根据ID删除景点")
    public Result delete(@PathVariable Long id){
        log.info("删除的景点ID：{}",id);

        attractionsService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据ID修改景点信息
     * @param attractions
     * @return
     */
    @PostMapping("/update")
    @CrossOrigin
    @ApiModelProperty("根据ID修改景点信息")
    public Result update(@RequestBody Attractions attractions){
        log.info("修改信息：{}",attractions);
        attractionsService.updateAttraction(attractions);
        return Result.success();
    }
}
